﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace DoAn
{
    public partial class frmSuaHang : Form
    {
        public frmSuaHang()
        {
            InitializeComponent();
        }
        public frmSuaHang(string MaHang):this()
        {
            HangHoaDTO hhDTO = new HangHoaDTO();
            HangHoaBUS hhBUS = new HangHoaBUS();
            hhDTO = hhBUS.LayHangTheoMa(MaHang);
            LoaiHangBUS lhBus = new LoaiHangBUS();             
            lbMaHang.Text = hhDTO.MaHang;
            txtTenHang.Text = hhDTO.TenHang;

            List<LoaiHangDTO> listlh = new List<LoaiHangDTO>();
            LoaiHangBUS lh = new LoaiHangBUS();
            listlh = lh.LayLoaiHang();
            cbbLoaiHang.DataSource = listlh;
            cbbLoaiHang.DisplayMember = "TenLoaiHang";
            cbbLoaiHang.ValueMember = "MaLoaiHang";

            List<NhaCCDTO> ListNhaCC = new List<NhaCCDTO>();
            NhaCCBUS ncc = new NhaCCBUS();
            ListNhaCC = ncc.LayNhaCC();
            cbbNhaCC.DataSource = ListNhaCC;
            cbbNhaCC.DisplayMember = "TenNCC";
            cbbNhaCC.ValueMember = "MaNCC";

            txtSoLuong.Text = hhDTO.SoLuong.ToString();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SuaHangHoa()
        {
            HangHoaDTO hh = new HangHoaDTO();
            hh.MaHang = lbMaHang.Text;
            hh.TenHang = txtTenHang.Text;
            hh.MaLoaiHang = int.Parse(cbbLoaiHang.SelectedValue.ToString());
            hh.MaNCC = int.Parse(cbbNhaCC.SelectedValue.ToString());
            hh.SoLuong = int.Parse(txtSoLuong.Text);

            HangHoaBUS hhBus = new HangHoaBUS();
            hhBus.SuaHangHoa(hh);
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            SuaHangHoa();
            this.Close();
        }

        private void txtTenHang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SuaHangHoa();
                this.Close();
            }
        }

        private void cbbLoaiHang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SuaHangHoa();
                this.Close();
            }
        }

        private void cbbNhaCC_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SuaHangHoa();
                this.Close();
            }
        }

        private void txtSoLuong_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SuaHangHoa();
                this.Close();
            }
        }

        private void frmSuaHang_Load(object sender, EventArgs e)
        {

        }
    }
}
